﻿<?php
	session_start();
	
	$situation = "";
	$oldNomSituation = "";
	$question = "";
	$reponses = "";
	
	
	
	if( isset($_POST['idQuestion']) && (!empty($_POST['idQuestion'])) )
	{
		if(isset($_SESSION['questions']) && (count($_SESSION['questions']) > 0) )
		{	
			//On récupère le nom de la situation
			$situation = '<input type="text" name="nomSituation" class="form_input_contact" value="'.htmlentities($_SESSION['questions'][$_POST['idQuestion']]['nomSituation']).'"/>';
			$oldNomSituation = '<input type="hidden" name="oldNomSituation" class="form_input_contact" value="'.htmlentities($_SESSION['questions'][$_POST['idQuestion']]['nomSituation']).'"/>';
			$situation .= "<label>Ce nom doit être unique</label>";
			
			//On récupère la question
			$question = '<input type="text" name="question" class="form_input_contact" value="'.htmlentities($_SESSION['questions'][$_POST['idQuestion']]['question']).'"/>';
			
			//On récupère les réponses
			$tabReps = $_SESSION['questions'][$_POST['idQuestion']]['reps'];
			foreach($tabReps as $value)
				$reponses .= '<div class="adminform_row_contact"><label class="adminleft">Réponse :</label><input type="text" name="reps[]" class="form_input_contact" value="'.htmlentities($value).'"/></div>';
			
		}
	}


?>


<form method="post" action="traitements/modifier_question.php" class="modifQuestion">
	
	<input type="hidden" name="idQuestion" value="<?php echo isset($_POST['idQuestion'])?$_POST['idQuestion']:'' ?>"/>
	
		<?php
			if($situation != "")
			{
				echo $oldNomSituation;
				echo "<div class='adminform_row_contact'>";
					echo "<label class='adminleft'>Nom Situation :</label>";
					echo $situation;
				echo "</div>";
			}
			
			echo "<div class='adminform_row_contact'>&nbsp;</div>";
			
			if($question != "")
			{
				echo "<div class='adminform_row_contact'>";
					echo "<label class='adminleft'>Question :</label>";
					echo $question;
				echo "</div>";
			}
			
			if($reponses != "")
			{
				echo "<div>";
					echo "<div class='adminform_row_contact'>";
						echo "<label class='adminleft'>&nbsp;</label>";
						echo "<img src='images/add.png' alt='addRep'/>";
					echo "</div>";
					
					echo $reponses;
				echo "</div>";
			}
			
			if( !empty($_POST['idQuestion']) )
				echo "<div class='adminform_row_contact'> <label class='adminleft'>&nbsp;</label> <input type='submit' name='valider' value='valider'/> </div>";
				
		?>		
	
</form>